/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * libburmese - Burmese Language Support Library
 * Copyright (C) 2011  Thura Hlaing <trhura@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * test_myctype.c - Tests for myctype.h
 * Created: 2011-01-07
 */

#include <burmese/myctype.h>
#include <stdio.h>
#include <assert.h>

#define length(var) (sizeof(var)/sizeof (var[0]))

wchar_t myconsonants[] = {
	0x1000, 0x1001, 0x1002, 0x1003, 0x1004,
	0x1005, 0x1006, 0x1007, 0x1008, 0x1009,
	0x100a, 0x100b, 0x100c, 0x100d, 0x100e,
	0x100f, 0x1010, 0x1011, 0x1012, 0x1013,
	0x1014, 0x1015, 0x1016, 0x1017, 0x1018,
	0x1019, 0x101a, 0x101b, 0x101c, 0x101d,
	0x101e, 0x101f, 0x1020, 0x1021
};

wchar_t mymedials[] = {
	0x103b, 0x103c, 0x103d, 0x103e
};

wchar_t myvowels[] = {
	0x102c, 0x102b, 0x102d, 0x102e, 0x102f,
	0x1030, 0x1031, 0x1032
};

wchar_t mytones[] = {
	0x1037, 0x1038
};

wchar_t mypuncts[] = {
    0x104a, 0x104b
};

wchar_t mydigits[] = {
    0x1040, 0x1041, 0x1042, 0x1043, 0x1044,
    0x1045, 0x1046, 0x1047, 0x1048, 0x1049
};

wchar_t myindependvowels[] = {
    0x1023, 0x1024, 0x1025, 0x1026, 0x1027,
    0x1029, 0x102a
};

wchar_t myindependsymbols[] = {
    0x104c, 0x104d, 0x104e, 0x104f
};

void test_function (int (*func) (wchar_t wc), wchar_t* arg)
{
    int _m = 0;
    
#define ASSERT_ARRAY(_function,  _array, _arraycheck)   \
    for (_m = 0; _m < length (_array); _m++) {          \
        int _isvar = func (_array[_m]);                 \
        if (_array == _arraycheck)                      \
            assert (_isvar != 0);                       \
        else                                            \
            assert (_isvar == 0);                       \
    }
    
    ASSERT_ARRAY (func, myconsonants, arg);
    ASSERT_ARRAY (func, mymedials, arg);
    ASSERT_ARRAY (func, myvowels, arg);
    ASSERT_ARRAY (func, mytones, arg);
}

int main(int argc, char *argv[])
{

#define STRINGIFY(n)    #n
#define TEST(func, arg) \
    fprintf (stdout, "Testing " STRINGIFY(func) " ...\n"); \
    test_function (&func, arg);

    TEST (my_wcismyindependvowel, myindependvowels);
    TEST (my_wcismyconsonant, myconsonants);
    TEST (my_wcismymedial, mymedials);
    TEST (my_wcismyvowel, myvowels);
    TEST (my_wcismypunct, mypuncts);
    TEST (my_wcismytone, mytones);
    TEST (my_wcismyindependsymbol, myindependsymbols);
    
	return 0;
}

